package strauss.flatland.things;

import java.awt.Color;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import strauss.flatland.things.geometry.Vertex;
import strauss.flatland.things.geometry.GeometricVector;

public class Dot extends Thing {
	private Vertex coordinate;
	private Color color;
	
	public Color getColor() {
		return color;
	}
	
	public double getMass() {
		return 1;
	}
	
	
	public Dot(Vertex coordinate, GeometricVector geometricVector) {
		super(geometricVector);
		this.coordinate = coordinate;
		Random rand = new Random();
		int r = Math.abs(rand.nextInt())%255;
		int g = Math.abs(rand.nextInt())%255;
		int b = Math.abs(rand.nextInt())%255;
		this.color=new Color(r,g,b);
	}
	/**
	 * @param coordinate
	 * @param geometricVector
	 */
	public Dot(Vertex coordinate, GeometricVector geometricVector, Color color) {
		super(geometricVector);
		this.coordinate = coordinate;
		this.color=color;
	}
	
	public List<Vertex> getCoordinates() {
		List<Vertex> coordinates = new ArrayList<Vertex>();
		coordinates.add(coordinate);
		return coordinates;
	}
	
	public void update() {
		// our central position is changed
		coordinate.translate(getGeometricVector());
	}

	public boolean contains(Point2D arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean contains(Rectangle2D arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean contains(double arg0, double arg1) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean contains(double arg0, double arg1, double arg2, double arg3) {
		// TODO Auto-generated method stub
		return false;
	}

	public Rectangle getBounds() {
		// TODO Auto-generated method stub
		return null;
	}

	public Rectangle2D getBounds2D() {
		Path2D.Double path = new Path2D.Double();
		path.moveTo(coordinate.getX(), coordinate.getY());
		path.lineTo(coordinate.getX()+getGeometricVector().getXD(), coordinate.getY()+getGeometricVector().getYD());
		path.closePath();
		return path.getBounds2D();
	}

	public PathIterator getPathIterator(AffineTransform arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	public PathIterator getPathIterator(AffineTransform arg0, double arg1) {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean intersects(Rectangle2D arg0) {
		Path2D.Double path = new Path2D.Double();
		path.moveTo(coordinate.getX(), coordinate.getY());
		path.lineTo(coordinate.getX()+getGeometricVector().getXD(), coordinate.getY()+getGeometricVector().getYD());
		path.closePath();
		boolean intersect = path.intersects(arg0);
		return intersect;
	}

	public boolean intersects(double arg0, double arg1, double arg2, double arg3) {
		// TODO Auto-generated method stub
		return false;
	}

	public Vertex getCenterOfGravity() {
		return coordinate;
	}

	public double getElasticity() {
		return 1;
	}
	
}
